class node(object):
    def __init__(self,i,a,b,c):
        self.i=i
        self.a=int(a)
        self.b=int(b)
        self.c=int(c)
def my_cmp(u,v):
    if u.a+u.b+u.c==v.a+v.b+v.c:
        if u.a==v.a:
            return u.i-v.i
        else:
            return v.a-u.a
    else:
        return (v.a+v.b+v.c)-(u.a+u.b+u.c)
n=int(raw_input())
f=[]
for i in range(1,n+1):
    # 注意这里一行后面的空格要去掉
    a,b,c =raw_input().split(' ')[:3]
    f.append(node(i,a,b,c))

f=sorted(f,cmp=my_cmp)
c=0
for a in f:
    print a.i,a.a+a.b+a.c
    c+=1
    if c==5:
        break